# App Engine imports
from google.appengine.ext import webapp

# Third party imports
import json

# OpenSocial Gifts imports
from db_model import PostalCode

class ApiServer(webapp.RequestHandler):
  """Handles requests to /sa_postal_codes URLs and reponds with JSON strings."""
  
  def get(self):
    """Respond with a JSON string representation of the lists of gifts."""
    codes = []
    for code in PostalCode.all():
      item = {'suburb' : code.suburb,
              'postal_code' : code.postal_code,
              'street_code' : code.street_code,
              'town' : code.town}
      codes.append(item)
    self.response.out.write(json.write(codes))
